/*
 * Classificator.cpp
 *
 *  Created on: 14/04/2009
 *      Author: evellyn, tamer, társis
 */

#include "Classificator.h"

#include <iostream>
#include <fstream>
#include <map>

using namespace std;

Classificator::Classificator() {

	reservedWords["int"] = "type";
	reservedWords["double"] = "type";
	reservedWords["char"] = "type";
	reservedWords["string"] = "type";
	reservedWords["input"] = "input";
	reservedWords["output"] = "output";
	reservedWords["not"] = "not";
	reservedWords["and"] = "and";
	reservedWords["or"] = "or";
	reservedWords["while"] = "while";
	reservedWords["if"] = "if";
	reservedWords["else"] = "else";
	reservedWords["begin"] = "begin";
	reservedWords["end"] = "end";

	arithmeticOperators["+"] = "+";
	arithmeticOperators["-"] = "-";
	arithmeticOperators["*"] = "*";
	arithmeticOperators["/"] = "/";
	arithmeticOperators["%"] = "%";
	arithmeticOperators["^"] = "^";
	arithmeticOperators["="] = "=";

	comparationOperators["<"] = "<";
	comparationOperators[">"] = ">";
	comparationOperators["<="] = "<=";
	comparationOperators[">="] = ">=";
	comparationOperators["=="] = "==";
	comparationOperators["!="] = "!=";

	delimiteres[","] = ",";
	delimiteres[";"] = ";";
	delimiteres["("] = "(";
	delimiteres[")"] = ")";
	delimiteres["["] = "[";
	delimiteres["]"] = "]";
	delimiteres["{"] = "{";
	delimiteres["}"] = "}";

	//literalCharacter[""]

}

string Classificator::getClass(int type, string lexeme) {
	const int NAME = 0;
	const int DIGIT = 1;
	const int OPERATOR = 2;
	const int DELIMITER = 3;
	const int LITERAL_CHARACTER = 4;

	switch (type) {
	case NAME:
		if (!reservedWords[lexeme].empty())
			return reservedWords[lexeme];
		else
			return "identifier";
		break;

	case DIGIT:
		if (lexeme.find('.') != string::npos)
			return "const_double";
		else
			return "const_int";
		break;

	case OPERATOR:
		if (!arithmeticOperators[lexeme].empty())
			return arithmeticOperators[lexeme];
		else
			return comparationOperators[lexeme];
		break;

	case DELIMITER:
		return delimiteres[lexeme];
		break;

	case LITERAL_CHARACTER:
		if (lexeme.find('\''))
			return "const_char";
		else
			return "const_string";

	default:
		return "";
	}
}

Classificator::~Classificator() {

}
